<?php
set_time_limit(0);

require_once "config.php";
require_once "irc.php";

$socket = irc_connect($config);

while(1) {
	while($data = fgets($socket)) {
		echo $data;
		flush();

		$ex = explode(' ', $data);
		$rawcmd = explode(':', $ex[3]);
		$oneword = explode('<br>', $rawcmd);
		$channel = $ex[2];
		$nicka = explode('@', $ex[0]);
		$nickb = explode('!', $nicka[0]);
		$nickc = explode(':', $nickb[0]);

		$host = $nicka[1];
		$nick = $nickc[1];
		if($ex[0] == "PING"){
			fputs($socket, "PONG ".$ex[1]."\n");
		}

		$args = NULL;
		for ($i = 4; $i < count($ex); $i++) { 
			$args .= $ex[$i] . ' '; 
		}
		
		print_r($rawcmd[1]);
		if ($rawcmd[1] == "!sayit") {
			echo ">>>>".$rawcmd[1];
			fputs($socket, "QUIT\n");
		}
		/*
		if ($rawcmd[1] == "!sayit") {
			fputs($socket, "PRIVMSG ".$channel." :".$args." \n");
		} elseif ($rawcmd[1] == "!md5") {
			fputs($socket, "PRIVMSG ".$channel." :MD5 ".md5($args)."\n");
		} elseif ($rawcmd[1] == "!whois") {
			fputs($socket, "WHOIS richard_ma\n");
		}
		*/
	}
}

?>